#include <iostream>
#include <algorithm>
using namespace std;
typedef struct{
    string name;
    double score;
}student;
int main(){
    int n;
    student a[100];
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i].name>>a[i].score;
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1-i;j++){
            if(a[j].score<a[j+1].score)
                swap(a[j],a[j+1]);
        }
    }
    for(int i=0;i<n;i++) cout<<a[i].name<<" "<<a[i].score<<endl;
}
